import java.io.Writer;
import java.util.concurrent.locks.ReadWriteLock;

public class test {
    private static Object lock = new Object();
    public static void main(String[] args) throws Exception {



        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行run()，thread线程状态：" + Thread.currentThread().getState());
                synchronized(lock) {
                }
                System.out.println("synchronized结束，thread线程状态：" + Thread.currentThread().getState());
            }
        });
        System.out.println("未调用start()，thread线程状态：" + thread.getState());
        synchronized(lock) {
            thread.start();
            Thread.sleep(2000);
            System.out.println("线程synchronized，thread线程状态：" + thread.getState());
        }
        Thread.sleep(2000);
        System.out.println("线程执行完成，thread线程状态：" + thread.getState());
    }

    public static void main1(String[] args) throws Exception {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行run()，thread线程状态：" + Thread.currentThread().getState());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("sleep结束，thread线程状态：" + Thread.currentThread().getState());
            }
        });
        System.out.println("未调用start()，thread线程状态：" + thread.getState());
        thread.start();
        Thread.sleep(200);
        System.out.println("线程sleep，thread线程状态：" + thread.getState());
        Thread.sleep(2000);
        System.out.println("线程执行完成，thread线程状态：" + thread.getState());
    }
}
